<?php

namespace common\jobs\base;

use Yii;

/**
 * 基础重试任务类
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
abstract class BaseRetryableJob extends BaseJob implements \yii\queue\RetryableJobInterface {

    /**
     * @inheritdoc
     */
    public $attempts = 5;

    /**
     * @inheritdoc
     */
    public function getTtr() {
        return 3;
    }

    /**
     * @inheritdoc
     */
    public function canRetry($attempt, $error) {
        if (YII_DEBUG) {
            Yii::error($error->getMessage(), __NAMESPACE__);
        }
        return $attempt < $this->attempts;
    }

}
